package ${jsonPackage};

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import ${entityPackage}.${domainObjectName};
import ${pagingInfo}.PagingInfo;
import ${paramsValidate}.ParamsValidate;
import ${servicePackage}.${domainObjectName}Service;

@Controller
@RequestMapping("/${lowerDomainObjectName}")
public class ${domainObjectName}Json {
    @Autowired
    ${domainObjectName}Service ${lowerDomainObjectName}Service;

    @RequestMapping("pagingList.json")
    @ResponseBody
    public Object pagingList(Model model,PagingInfo pagingInfo) {
        return ${lowerDomainObjectName}Service.pagingList(pagingInfo);
    }

    @RequestMapping("list.json")
    @ResponseBody
    public Object list(Model model) {
        return ${lowerDomainObjectName}Service.list();
    }
    
    @RequestMapping("save.json")
    @ResponseBody
    @ParamsValidate
    public Object save(Model model,${domainObjectName}Key ${lowerDomainObjectName}) {
        ${lowerDomainObjectName}Service.save(${lowerDomainObjectName});
        return null;
    }
    
    @RequestMapping("deleteById.json")
    @ResponseBody
    public Object delete(Model model,@RequestParam("ids")String ids) {
        List<${domainObjectName}Key> keys = new ArrayList<>();
        for (String k : ids.split(";")) {
            String[] key = k.split(":");
            keys.add(new ${domainObjectName}Key(key[0],key[1]));
        }
        ${lowerDomainObjectName}Service.delete(keys);
        return null;
    }

    @RequestMapping("delete.json")
    @ResponseBody
    public Object delete(PagingInfo pagingInfo) {
    	${lowerDomainObjectName}Service.delete(pagingInfo);
        return null;
    }
}
